<?

require_once("mysql.php");
require_once("user.php");
require_once("friends.php");
require_once("session.php");

SESSION();

function update_login_table($userid, $in) {
    $q = "INSERT INTO login (userid, login, time) VALUES (USERID, LOGIN, UNIX_TIMESTAMP(NOW()) )";
	$q = str_replace(array("USERID", "LOGIN" ), array($userid, $in ? "TRUE" : "FALSE"), $q);
	MYSQL_Q($q);
}

function login($userid, $username, $token) {

    $_SESSION['userid'] = $userid;
	$_SESSION['username'] = $username;
	$_SESSION['token'] = $token;

    find_or_create_user();
	update_login_table($userid, TRUE);
	build_facebook_friends_list(TRUE);
}

function logout($userid) {

    update_login_table($userid, FALSE);

}

?>